<%--
  Created by IntelliJ IDEA.
  User: 86153
  Date: 2023/3/27
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>


<html>
  <head>
    <base href="<%=basePath%>">
    <script src="js/jquery-3.6.0.js"></script>
    <script>
      function Insert_Bulletin(e) {
        var formObject = {};
        var formArray = $("#form2").serializeArray();
        $.each(formArray, function (i, item) {
          formObject[item.name] = item.value;
        });
        $.ajax({
          url: 'bulletin/Insert_Bulletin',
          headers: {
            'Content-Type': 'application/json;charset=utf-8',
          },
          type: 'POST',
          data: JSON.stringify(formObject),
          dataType: "json",
          success: function (data) {
            if(data.code=='1000'){
              alert("添加失败，请重试");
              window.location.reload();
            }else if(data.code=='1001'){
              alert("添加成功");
              window.location.href='bulletin/all_bulletin';
            }else if(data.code=='1002'){
              alert("标题已经存在，请重新输入！");
              window.location.reload();
            }
          }
        })
      }
    </script>
  </head>
  <body>
  <form id="form2">
    <div id="Popup">
      <div id="SubPopup">
        <div class="form_boxC">
          <table cellpadding="0" cellspacing="0">
            <tr style="position: absolute;top: 80px;left: 300px;">
              <th>标题 <span class="f_cB"></span></th>
              <td>
                <div class="txtbox floatL" style="width: 666px;height: 50px;text-align: center;position: relative;left: 20px;">
                  <input style="width: 666px;height: 100%;word-break: break-all;" name="title" type="text" size="20"  placeholder="请输入标题">
                </div>
              </td>
            </tr>
            <tr style=" position: absolute; top: 180px;left: 300px;>
              <th>内容 <span class=">
              <th>内容 <span class="f_cB"></span></th>
              <td style=" position: relative;left: 20px;">
                <div class="txtbox floatL" style="width: 666px;height: 300px;">
                  <textarea cols="40" style="width: 666px;height: 100%;" name="content" placeholder="请输入内容"></textarea>
                </div>
              </td>
            </tr>
          </table>
        </div>
        <div id="BtmBtn">
          <div class="btn_boxB floatR mag_l20">
            <button style="cursor: pointer;background-color: #36c4aa;color: white;padding: 12px 20px;display: inline-block;font-size: 15px;right: 10%;position: absolute;top: 70%;" type="submit" onclick="Insert_Bulletin()">确定</button>
          </div>
          <div class="btn_box floatR">
            <button style="cursor: pointer;background-color: #36c4aa;color: white;padding: 12px 20px;display: inline-block;font-size: 15px;top: 70%;position: absolute;right: 3.5%;"><a style="color: white; text-decoration:none;" href="bulletin/all_bulletin">返回</a></button>
          </div>
        </div>
      </div>
    </div>
  </form>
  </body>
</html>
